package com.lyu.xiaolvshu.note.biz.consumer;

import com.lyu.xiaolvshu.note.biz.constant.MqConstants;
import com.lyu.xiaolvshu.note.biz.service.NoteService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@RocketMQMessageListener(consumerGroup = "xiaolvshu_group_" + MqConstants.TOPIC_DELETE_NOTE_LOCAL_CACHE, topic = MqConstants.TOPIC_DELETE_NOTE_LOCAL_CACHE, messageModel = MessageModel.BROADCASTING)
public class DeleteNoteLocalCacheConsumer implements RocketMQListener<String> {

    @Resource
    private NoteService noteService;

    @Override
    public void onMessage(String message) {
        Long nodeId = Long.valueOf(message);
        log.info("## 消费者消费成功, noteId: {}", message);
        noteService.deleteNoteLocalCache(nodeId);
    }
}
